/*
 * @(#)LoginController.java 2020-07-09
 *
 * Copyright (c) 2010 by rayootech.com. All rights reserved.
 */
package com.nuctech.formlogin.web;

import com.nuctech.formlogin.utils.VerifyCode;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 * 登录控制器
 *
 * @author lilu
 * @date 2020-07-09
 * @since 1.0.0
 */
@RestController
public class LoginController {

	@GetMapping("/verifycode")
	public void verifyCode(HttpServletRequest request, HttpServletResponse response) throws IOException {
		VerifyCode vc = new VerifyCode();
		BufferedImage image = vc.getImage();
		String text = vc.getText();
		HttpSession session = request.getSession();
		session.setAttribute("verify_code", text);
		VerifyCode.output(image, response.getOutputStream());
	}

}
